<template>
	<view class="page">
		<view class="page__head center">
			<u-search placeholder="请输入关键字" :showAction="false" v-model="keyword" @search="search"></u-search>
		</view>
		<view class="page__content">
			<view class="list" v-for="(item,index) in list" :key="index" @click="openForm(item)">
				<view class="list__cover">
					<image :src="item.cover" mode=""></image>
				</view>
				<view class="list__title ellipsis">{{item.FormTitle}}</view>
			</view>
			<view class="no-data center" v-show="noData">抱歉，未查询到数据(￣▽￣)</view>
		</view>
	</view>
</template>

<script>
	import _custom from '@/common/_custom.js';
	import _data from '@/common/_data.js'
	
	export default {
		data() {
			return {
				static_img: _data.data('static_img'),
				keyword: '',
				list: [],
				noData: false
			}
		},
		methods: {
			/**
			 * 获取表单模板列表
			 * @param {Object} v
			 */
			getSmartFormList(v) {
				let that = this;
				_custom.getDataJava({
					apiname: 'getSmartFormList',
					apiparam: {
						keyword: v, //关键词模糊查询
						typename: "",
						sorting: "asc", //asc:最早，desc:最新            
						isdraft: "0", //0:已发布，1:暂存在草稿
					},
					success(res) {
						res.forEach(item => {
							item.cover = that.static_img + '/' + item.CoverImage;
						})
						that.list = res;
						if(!res.length) that.noData = true;
					},
				})
			},
			openForm(v) {
				let obj = JSON.parse(JSON.stringify(v));
				let json = v.FormJson.replace(/%22/g,'"');
				try {
					obj.FormJson = JSON.parse(json);
				} catch(e) {
					console.log(e)
				}
				uni.navigateTo({
					url: '../smart-form-add/view?type=1&data=' + JSON.stringify(obj)
				})
			},
			search(e) {
				this.getSmartFormList(e)
			}
		}
	}
</script>

<style scoped lang="scss">
	.page {
		min-height: 100vh;
		
		&__head {
			height: 100rpx;
			padding: 0 20rpx;
			box-sizing: border-box;
			border-bottom: 1rpx solid #eee;
			background-color: #fff;
		}
		
		&__content {
			padding: 0 20rpx;
			padding-bottom: 20rpx;
			box-sizing: border-box;
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;
		}
	}
	
	.list {
		width: 340rpx;
		border-radius: 20rpx;
		flex-shrink: 0;
		margin-top: 40rpx;
		
		&__cover {
			height: 180rpx;
			
			image {
				width: 100%;
				height: 100%;
				border-radius: 20rpx 20rpx 0 0;
			}
		}
		
		&__title {
			height: 80rpx;
			font-size: 35rpx;
			padding: 0 20rpx;
			line-height: 80rpx;
			background-color: #fff;
			border-radius: 0 0 20rpx 20rpx;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}
	}
	
	.no-data {
		height: 400rpx;
		width: 100%;
		font-size: 27rpx;
		text-align: center;
	}
</style>
